package com.kittlen.managementSystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kittlen.managementSystem.entity.MySqlLimit;
import com.kittlen.managementSystem.entity.Result;
import com.kittlen.managementSystem.entity.VEvaluate;
import com.kittlen.managementSystem.service.IVEvaluateService;
import com.kittlen.managementSystem.utils.ObjectUtil;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评论(选择表主) 前端控制器
 * </p>
 *
 * @author kittlen
 * @since 2021-02-09
 */
@RestController
@RequestMapping("/vEvaluate")
public class VEvaluateController {

    @Resource
    IVEvaluateService ivEvaluateService;

    @RequestMapping("/selects")
    public Result selects(VEvaluate vEvaluate,@RequestParam(required = false,defaultValue = "0")int page,
                          @RequestParam(required = false,defaultValue = "0")int limit){
        Result result=new Result();
        QueryWrapper<VEvaluate> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNoEmpty(vEvaluate.getEvaluateId())){
            queryWrapper.eq("evaluate_id", vEvaluate.getEvaluateId());
        }
        if(ObjectUtil.isNoEmpty(vEvaluate.getChoiceId())){
            queryWrapper.eq("choice_id", vEvaluate.getChoiceId());
        }
        if(ObjectUtil.isNoEmpty(vEvaluate.getCoachId())){
            queryWrapper.eq("coach_id", vEvaluate.getCoachId());
        }
        if(ObjectUtil.isNoEmpty(vEvaluate.getStudentId())){
            queryWrapper.eq("student_id", vEvaluate.getStudentId());
        }
        if(ObjectUtil.isNoEmpty(vEvaluate.getStageEnd())){
            queryWrapper.eq("stage_end", vEvaluate.getStageEnd());
        }
        if (page!=-1) {
            MySqlLimit mySqlLimit=new MySqlLimit(page,limit);
            queryWrapper.last("LIMIT "+mySqlLimit.getOffset()+","+mySqlLimit.getRows());
        }
        queryWrapper.orderByDesc("create_date");
        List<VEvaluate> list=ivEvaluateService.list(queryWrapper);
        result.setData(list);
        queryWrapper.last("");
        result.setCount(ivEvaluateService.count(queryWrapper));
        return result;
    }
}
